
#ifndef CFF_PARSER_H
#define CFF_PARSER_H

#include <cffexport.h>
#include <list>
#include <map>
#include <string>
#include <vector>
#include <iobject.h>

class CFF_API cffAttribute
{
private:
	bool				_valid;
  std::string _key;
  std::string _value;

public:
	cffAttribute ();
	cffAttribute (const char* value);
	cffAttribute (const char* key, const char* value);
	bool IsValid () const;

	int AsInt () const;
	float AsFloat () const;

  operator const char* () {
    return _value.c_str();
  }

	operator const char* () const {
    return _value.c_str();
	}

	void Debug ();
};

class CFF_API cffAttributes
{
private:
	cffAttribute							_null;
	std::vector<cffAttribute>	_attributes;
	std::map<std::string, cffAttribute>	_namedAttributes;
public:
	cffAttributes ();

	void SetAttribute (const char* key, const char* value);
	void AddAttribute (const char* value);

	unsigned GetNumberOfAttributes () const;
	bool HasAttribute (unsigned idx) const;
	bool HasNamedAttribute (const char* name) const;

	const cffAttribute& GetAttribute(unsigned idx) const;
	const cffAttribute& GetNamedAttribute (const char* name) const;

	void Debug ();

};

class CFF_API cffNode : public iObject
{
	CE_OBJECT
private:
	std::list<cffNode*>	_nodes;
	cffNode							*_parent;

	std::string					_name;

	cffAttributes				_attributes;

protected:
	void PrintIndent (int indent);

public:
	cffNode ();
	~cffNode ();

	cePtr<cffNode> GetParent () const;
	void AddNode (cffNode* node);

	unsigned GetNumberOfNodes (const char* name = 0) const;
	cffNode* GetFirstNode ();
	cffNode* GetNode (unsigned idx);
	cffNode* GetNode (const char* name, unsigned idx = 0);


	const cffAttributes& GetAttributes () const;
	cffAttributes& GetAttributes ();

	bool HasAttribute (unsigned idx) const;
	bool HasNamedAttribute (const char* name) const;


	const cffAttribute& GetAttribute (unsigned idx) const;
	const cffAttribute& GetNamedAttribute (const char* name) const;


	void SetName (const char* name);
	const char* GetName () const;

	virtual void Debug (int indent = 0);
};

class CFF_API cffParser
{
public:
	cffParser();

	ceRef<cffNode> Parse (const char* filename);
	ceRef<cffNode> ParseFromBuffer (const char *buffer);
};

#endif // CFF_PARSER_H
